<?php

if(!defined('IN_ECS'))
{
	die('Hacking attempt');
}

if(!defined('EC_CHARSET'))
{
	define('EC_CHARSET', 'utf-8');
}

class JSON
{
	var $at = 0;
	var $ch = '';
	var $text = '';
	
	function encode($arg,$force = true)
	{
		static $_force;
		if(is_null($_force))
		{
			$_force = $force;
		}
		
		if($_force && EC_CHARSET == 'utf-8' && function_exists('json_encode'))
		{
			return json_encode($arg);
		}
		
		$returnValue = '';
		$c			 = '';
		$i			 = '';
		$l			 = '';
		$s			 = '';
		$v			 = '';
		$numeric	 = true;
		
		switch(gettype($arg))
		{
			case 'array':
				foreach($arg as $i=>$v)
				{
					if(!is_numeric($i))
					{
						$numeric = false;
						break;
					}
				}
				
				if($numeric)
				{
					foreach($arg as $i=>$v)
					{
						if(strlen($s) > 0)
						{
							$s .= ',';
						}
						$s .= $this->encode($arg[$i]);
					}
					
					$returnValue = '[' . $s . ']';
				}
				else 
				{
					foreach($arg as $i=>$v)
					{
						if(strlen($s)>0)
						{
							$s .= ',';
						}
						$s.=$this->encode($i).':'.$this->encode($arg[$i]);
					}
					
					$returnValue = '{'.$s.'}';
				}
				break;
				
			case 'object':
				
				
				break;
			
			case 'integer':
				
			case 'double':
				
			case 'string':
				
			case 'boolean':
				
			default:
				$returnValue = 'null';
		}
		
		return $returnValue;
	}
	
	function decode($text,$type=0)
	{
		
	}
	
	function error($m)
	{
		
	}
	
	function next()
	{
		
	}
	
	function str()
	{
		
	}
	
	function arr()
	{
		
	}
	
	function obj()
	{
		
	}
	
	function assoc()
	{
		
	}
	
	function num()
	{
		
	}
	
	function word()
	{
		
	}
	
	function val()
	{
		
	}
	
	function object_to_array($obj)
	{
		
	}
}